package cn.edu.huanu.service.impl;

import cn.edu.huanu.dao.UserDao;
import cn.edu.huanu.dao.impl.UserDaoImpl;
import cn.edu.huanu.exception.BussiessException;
import cn.edu.huanu.pojo.User;
import cn.edu.huanu.service.UserService;

/**
 * @author hb
 * @date 2025-10-17 15:54:34
 */
public class UserServcieImpl implements UserService {
    //业务逻辑的实现依赖数据访问层
    private UserDao userDao=new UserDaoImpl();

    @Override
    public User login(String username, String pwd) throws BussiessException {
        //对username,pwd的格式进行校验

        User user = userDao.queryUserByUsernameAndPwd(username, pwd);
        if(user==null){
            throw new BussiessException("用户名或密码错误");
        }
        return user;
    }

    @Override
    public void regiester(User user) throws BussiessException {
            //对username,pwd（密码长度不能少于六位）的格式进行校验
            //对用户名进行唯一性校验
          User u= userDao.queryUserByUserName(user.getUsername());
          if(u!=null){
              throw new BussiessException("用户名已存在");
          }
           userDao.insertUser(user);
    }
}
